package System;
import java.util.Properties;
import java.io.*;

public class Settings_System {

	private static Properties MyProperties;	
		
	private static final String PropertiesFileName="cfg/system.xml";
	public static final String PropertyKeys[] = {"Language"};
	
	private static final int Property_Language 		= 0;
	
	public static final String LanguageNames[] = {"Englisch","Deutsch","Unknown"};
	
	public static final int LANGUAGE_ENGLISCH=0;
	public static final int LANGUAGE_GERMAN=LANGUAGE_ENGLISCH+1;
	public static final int LANGUAGE_UNKNOWN=LANGUAGE_GERMAN+1;

	private static int ActiveLanguage;

	public Settings_System() {
		SetDefaults();
	}

	/****************************************************************************/
	/*																			*/
	/*	SetDefaults										Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Ststus : working	*/
	/*																			*/
	/****************************************************************************/
	private static void SetDefaults() {
		ActiveLanguage=LANGUAGE_ENGLISCH;
	}

/************************* Language functions *****************************************/

	/****************************************************************************/
	/*																			*/
	/*	GetActiveLanguage								Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	
	public static int GetActiveLanguage() {
		return(ActiveLanguage);	
	}

	/****************************************************************************/
	/*																			*/
	/*	SetActiveLanguage								Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	public static void SetActiveLanguage(String NewActiveLanguage) {
		int iCounter=0;
		
		while (!NewActiveLanguage.equals(LanguageNames[iCounter])) {
		iCounter++;
		if (iCounter>=LanguageNames.length)
			break;
		}
	
		if (iCounter<LANGUAGE_UNKNOWN) {
			ActiveLanguage=iCounter;
		} else {
			ActiveLanguage=LANGUAGE_ENGLISCH;
		}
	}

	/****************************************************************************/
	/*																			*/
	/*	SetActiveLanguage								Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	public static void SetActiveLanguage(int NewActiveLanguage) {
		if (NewActiveLanguage >=LanguageNames.length) {
			ActiveLanguage=LANGUAGE_ENGLISCH;
		} else {
			ActiveLanguage =NewActiveLanguage;
		}
	}

	/****************************************************************************/
	/*																			*/
	/*	GetLanguageName									Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	
	public static String GetLanguageName(int iLanguage) {
		if (iLanguage >=LanguageNames.length) {
			iLanguage=LANGUAGE_UNKNOWN;
		}
	
		return(LanguageNames[iLanguage]);	
	}






//SymbolDirectory="";

/*************************** Keys Functions *********************************************/

/*
String GetGlobalKey(int KeyNumber)
{
String KeyValue;	

if (KeyNumber<PropertyKeys.length)
	{
	KeyValue=MyProperties.getProperty(PropertyKeys[KeyNumber]);
		if (KeyValue==null)
			KeyValue="";
	}
	else
		KeyValue="";

return(KeyValue);	
}	

void SetGlobalKey(int KeyNumber,String KeyValue)
{
if (KeyNumber<PropertyKeys.length)
	{
	MyProperties.setProperty(PropertyKeys[KeyNumber],KeyValue);
	}
}	
*/

	/****************************************************************************/
	/*																			*/
	/*	GetPropertyKeyWithPostfix						Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	private String GetPropertyKeyWithPostfix(int Property,int iPostfix) {
		return(MyProperties.getProperty(PropertyKeys[Property]+iPostfix));
	}

	/****************************************************************************/
	/*																			*/
	/*	SetPropertyKey									Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	private static void SetPropertyKey(int Property,String PropertyValue) {
		MyProperties.setProperty(PropertyKeys[Property],PropertyValue);
	}

	/****************************************************************************/
	/*																			*/
	/*	SetPropertyKeyWithPostfix						Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/	
	private void SetPropertyKeyWithPostfix(int Property,int iPostfix,String PropertyValue) {
		MyProperties.setProperty(PropertyKeys[Property]+iPostfix,PropertyValue);
	}



/************************************ Load & Save Methods *******************************/

	/****************************************************************************/
	/*																			*/
	/*	LoadProperties									Author OG				*/
	/*																			*/
	/*	Description																*/
	/*																			*/
	/*	Version	1.0				Date 2009.12.9				Status : working	*/
	/*																			*/
	/****************************************************************************/
	public static void LoadProperties() {
		MyProperties = new Properties();
		FileInputStream MyPropertyFile;
		String TmpString;
	
		SetDefaults();
	
		try {
			MyPropertyFile = new FileInputStream(PropertiesFileName);
			MyProperties.loadFromXML(MyPropertyFile);
			MyPropertyFile.close();
		} catch (Exception e) {
			// do nothing
		}
		
		TmpString=MyProperties.getProperty(PropertyKeys[Property_Language]);
		if (TmpString!=null) {
			SetActiveLanguage(TmpString);
		} else {
			SetActiveLanguage(LANGUAGE_ENGLISCH);	
		}
		
		FileOutputStream MyPropertyOutFile;
		try {
			MyPropertyOutFile = new FileOutputStream(PropertiesFileName);
			MyProperties.storeToXML(MyPropertyOutFile,"mcSPS System Settings");
			MyPropertyOutFile.close();
		} catch (Exception e) {
		  // do nothing	
		}
	}
}